package com.gimi.cloud.jimi.client.controller.product;


import com.gimi.cloud.jimi.client.service.product.ProductService;
import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.reqhead.Response;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.dto.product.ProductDto;
import com.gimi.cloud.jimi.dto.product.ProductSkuDto;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "product")
public class ProductController {
    @Autowired
    private ProductService productService;
    private final static Logger logger = LoggerFactory.getLogger(ProductController.class);

    @RequestMapping(value = "/getProductDetail")
    public void getProductDetail(@RequestBody ProductDto productDto, HttpServletResponse response) throws Exception {
        Response resp = new Response();
        ProductDto dto = productService.getProductDetail(productDto);
        resp.setRes_data(dto);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }

    @RequestMapping(value = "/getProductProp")
    public void getProductProp(@RequestBody ProductDto productDto, HttpServletResponse response) throws Exception {
        logger.info("请求参数==>" + productDto);
        Response resp = new Response();
        List<Map<String, Object>> prop = productService.getProductProp(productDto);
        resp.setRes_data(prop);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }

    @RequestMapping(value = "/getModelValueList")
    public void getModelValueList(@RequestBody ProductDto productDto, HttpServletResponse response) throws Exception {
        logger.info("请求参数==>" + productDto);
        Response resp = new Response();
        List<ProductSkuDto> list = productService.getModelValueList(productDto);
        resp.setRes_data(list);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }


}
